package com.hzsk.lisence.controller;

import com.github.pagehelper.PageInfo;
import com.hzsk.lisence.entity.EmProducePlanEntity;
import com.hzsk.lisence.entity.request.ProducePlanRequest;
import com.hzsk.lisence.entity.response.IncResponce;
import com.hzsk.lisence.service.EmProducePlanService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @Description :
 * @Date : 2024/8/14
 * @Author : ChenJin
 * @Version : v1.0.0
 **/
@CrossOrigin
@RestController
@RequestMapping("/api/lisence/plan")
public class EmProducePlanController {
    
    @Resource
    private EmProducePlanService emProducePlanService;

    @PostMapping("/sync")
    @ApiOperation(value = "同步生产计划")
    public IncResponce syncPlan(@RequestBody EmProducePlanEntity emProducePlanEntity){
        IncResponce incResponce = new IncResponce();
        try {
            Boolean result = emProducePlanService.syncProducePlan(emProducePlanEntity);
            incResponce.setData(result);
            incResponce.setCode(0);
        } catch (Exception e) {
            incResponce.setCode(-1);
            incResponce.setErrorMessage(e.getMessage());
            e.printStackTrace();
        }
        return incResponce;
    }
    
    @PostMapping("/getIdcPlanPage")
    @ApiOperation(value = "分页查询IDC生产计划")
    public IncResponce getIdcPlanPage(@RequestBody ProducePlanRequest producePlanRequest){
        IncResponce incResponce = new IncResponce();
        try {
            PageInfo<EmProducePlanEntity> idcPlanPage = emProducePlanService.getIdcPlanPage(producePlanRequest);
            incResponce.setData(idcPlanPage);
            incResponce.setCode(0);
        } catch (Exception e) {
            incResponce.setCode(-1);
            incResponce.setErrorMessage(e.getMessage());
            e.printStackTrace();
        }
        return incResponce;
    }

    @GetMapping("/getIdcPlanDetail")
    @ApiOperation(value = "查询IDC生产详情")
    public IncResponce getProducePlanDetail(@RequestParam Integer id){
        IncResponce incResponce = new IncResponce();
        try {
            EmProducePlanEntity idcPlanDetail = emProducePlanService.getIdcPlanDetail(id);
            incResponce.setData(idcPlanDetail);
            incResponce.setCode(0);
        } catch (Exception e) {
            incResponce.setCode(-1);
            incResponce.setErrorMessage(e.getMessage());
            e.printStackTrace();
        }
        return incResponce;
    }

    @PostMapping("/getNcPlanPage")
    @ApiOperation(value = "分页查询IDC生产计划")
    public IncResponce getNcPlanPage(@RequestBody ProducePlanRequest producePlanRequest){
        IncResponce incResponce = new IncResponce();
        try {
            PageInfo<EmProducePlanEntity> ncPlanPage = emProducePlanService.getNcPlanPage(producePlanRequest);
            incResponce.setData(ncPlanPage);
            incResponce.setCode(0);
        } catch (Exception e) {
            incResponce.setCode(-1);
            incResponce.setErrorMessage(e.getMessage());
            e.printStackTrace();
        }
        return incResponce;
    }

    @GetMapping("/getNcPlanDetail")
    @ApiOperation(value = "查询数控装置上产计划详情")
    public IncResponce getNcPlanDetail(@RequestParam Integer id){
        IncResponce incResponce = new IncResponce();
        try {
            EmProducePlanEntity ncPlanDetail = emProducePlanService.getNcPlanDetail(id);
            incResponce.setData(ncPlanDetail);
            incResponce.setCode(0);
        } catch (Exception e) {
            incResponce.setCode(-1);
            incResponce.setErrorMessage(e.getMessage());
            e.printStackTrace();
        }
        return incResponce;
    }
    
}
